/*-----------------------------------------------------------------------------
	The contents of this file are subject to the Mozilla Public License
	Version 1.1 (the "License"); you may not use this file except in
	compliance with the License. You may obtain a copy of the License at
	http://www.mozilla.org/MPL/
	
	Software distributed under the License is distributed on an "AS IS"
	basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
	License for the specific language governing rights and limitations
	under the License.
	
	The Original Code is Fever Framework code.
	
	The Initial Developer of the Original Code is Romain Ecarnot.
	Portions created by Initial Developer are Copyright (C) 2006
	the Initial Developer. All Rights Reserved.
	
	Contributor(s):
	
	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	See the License for the specific language governing permissions and
	limitations under the License.
-----------------------------------------------------------------------------*/

import com.bourre.utils.SharedObjectUtils;

import fever.Fever;

/**
 * Used by {@link fever.ioc.plugin.FeverPlugin} configration loader to map 
 * configuration xml object.
 *
 * @author Romain Ecarnot
 */
dynamic class fever.ioc.conf.PluginConfiguration
{
	//-------------------------------------------------------------------------
	// Private properties
	//-------------------------------------------------------------------------
	
	private var _success : Boolean;
	private var _sBaseURL : String;
	
	
	//-------------------------------------------------------------------------
	// Public properties
	//-------------------------------------------------------------------------
	
	/** Configuration loading status. */
	public function get success() : Boolean { return _success; }
	
	/** Object with paths properties. */
	public var paths : Object;
	
	/** Object with localisation properties. */
	public var locales : Object;
	
	/** Object with fonts properties. */
	public var fonts : Object;
	
	/** Object with themes properties. */
	public var themes : Object;
	
	/** Object with bitmaps properties. */
	public var bitmaps : Object;
	
	/** Object with sounds properties. */
	public var sounds : Object;
	
	/** Object with dll properties. */
	public var dll : Object;
	
	/** Path for localisation files. */
	public var localeURL : String;
	
	/** Path for font libraries. */
	public var fontURL : String;
	
	/** Path for theme libraries. */
	public var themeURL : String;
	
	/** Path for bitmaps. */
	public var bitmapURL : String;
	
	/** Path for sounds. */
	public var soundURL : String;
	
	/** Path for sounds. */
	public var dllURL : String;
	
	 
	//-------------------------------------------------------------------------
	// Public API
	//-------------------------------------------------------------------------
	
	/**
	 * Constructor.
	 */
	public function PluginConfiguration( baseURL : String )
	{
		_success = true;
		_sBaseURL = baseURL;
	} 	
	
	/**
	 * Returns the full qualified path to localisation files.
	 */
	public function getLocalePath() : String
	{
		return _sBaseURL + localeURL;	
	}
	
	/**
	 * Returns the full qualified path to font libraries.
	 */
	public function getFontPath() : String
	{
		return _sBaseURL + fontURL;	
	}
	
	/**
	 * Returns the full qualified path to bitmaps.
	 */
	public function getBitmapPath() : String
	{
		return _sBaseURL + bitmapURL;
	}
	
	/**
	 * Returns the full qualified path to bitmaps.
	 */
	public function getSoundPath() : String
	{
		return _sBaseURL + soundURL;
	}
	
	/**
	 * Returns the full qualified path to dll folders.
	 */
	public function getDLLPath() : String
	{
		return _sBaseURL + dllURL;
	}
	
	/**
	 * Fever internal used.
	 */
	public function invalidate() : Void
	{
		_success = false;	
	}
	
	/**
	 * Retreives passed-in {@code propName} property stored in Application 
	 * SharedObject.
	 */
	public function load( propName : String ) 
	{
		if( !propName ) propName = '.default';
		return SharedObjectUtils.loadLocal( Fever.application.name, propName );	
	}
	
	/**
	 * Stores passed-in {@code propValue} value in Application 
	 * SharedObject under {@code propName} name.
	 */
	public function save( propName : String, propValue ) : Void
	{
		if( !propName ) propName = '.default';
		
		SharedObjectUtils.saveLocal( 
			Fever.application.name, 
			propName, 
			propValue 
		);
	}
	
}